package model

import (
	"gorm.io/gorm/clause"
	"server/common"
)

// 研发流程
type FlowResearch struct {
	Model
	Commit     string `json:"commit"`
	User       string
	Desc       string //commit提交描述
	TesterDesc string //测试给予验证建议

	RepairBug bool `json:"repair_bug"` // 是否为修改bug
	BugID     uint

	NewFunc bool //是否为新增功能
}

func (flow *FlowResearch) Create() error {
	if err := common.DB.Create(&flow).Error; err != nil {
		return err
	}
	return nil
}

func (flow *FlowResearch) Info() error {
	if err := common.DB.Where("id = ?", flow.ID).Preload(clause.Associations).First(&flow).Error; err != nil {
		return err
	}
	return nil
}

func (flow *FlowResearch) Update() error {
	if err := common.DB.Where("id = ?", flow.ID).Omit("Nodes.*").Updates(&flow).Error; err != nil {
		return err
	}
	return nil
}

func (flow *FlowResearch) Delete() error {
	if err := common.DB.Where("id = ?", flow.ID).Delete(&flow).Error; err != nil {
		return err
	}
	return nil
}
